<template>
  <a-card :bordered="false" >
    <!-- 操作按钮区域 -->
    <div class="table-operator" style="margin-bottom: 0px">
      <a-button @click="refurbish" type="primary"  >刷新数据</a-button>
      <a-button @click="downLoadExcel" :headers="tokenHeader" type="primary" icon="audit" v-has="'rlgl:download'">下载模板</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" v-has="'rlgl:import'" :action="importExcelUrl" :customRequest="customRequest" >
        <a-button type="primary" icon="import">导入</a-button>
      </a-upload>
      <a-button @click="showModal" :headers="tokenHeader" type="primary" icon="audit" v-has="'rlgl:downLoadInit'">下载初始化数据</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('个人客户信息表')">导出</a-button>-->
    <!--  <a-button type="primary" icon="download" @click="handleExport('个人客户信息表变量,0')" v-has="'grkh:export'">导出变量</a-button>
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader"  v-has="'grkh:import'"  :action="importExcelUrl" :customRequest="customRequest">
        <a-button type="primary" icon="import">导入变量</a-button>
      </a-upload>
      <a-button type="primary" icon="download" @click="handleExport('个人客户信息表全量,1')" v-has="'grkh:export'">导出全量</a-button>
      <a-button @click="handleCheck('check,GRKHXX')" type="primary" icon="check-square" v-has="'dgkh:check'">校验</a-button>
      &lt;!&ndash; <a-button @click="handleExportXls('校验结果表,GRKHXX')" type="primary" icon="download">下载校验结果</a-button>&ndash;&gt;
      <a-button @click="handleExportXlsCheck('校验结果表,GRKHXX')" type="primary" icon="download" v-has="'dgkh:downloadResult'">下载校验结果</a-button>
      <a-button @click="handleCommit('commit,GRKHXX')" type="primary" icon="check" v-has="'dgkh:submit'">提交</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete" v-has="'dgkh:batchDel'"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>-->

      <!-- 高级查询区域 -->
      <!--<j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->


    </div>

    <a-calendar @select="onSelect">
      <ul slot="dateCellRender" slot-scope="value" class="events" >
        <li v-for="(item,i) in getListData(value)" :key="item.content" @click="test(getListData(value))" ref="menuItem">
          <a-tooltip placement="right" :title="item.content">
            <a-badge :status="item.type" :text="item.content" />
          </a-tooltip>
        </li>
      </ul>

      <template slot="monthCellRender" slot-scope="value">
        <div v-if="getMonthData(value)" class="notes-month">
        </div>
      </template>
    </a-calendar>
    <editCalendarModal ref="editCalendarModal"></editCalendarModal>
  </a-card>

</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { downFile,httpAction } from '@/api/manage'
  import moment from 'moment';
  import editCalendarModal from './editCalendarModal'

  export default {
    name: 'calendarList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      editCalendarModal
    },
    data () {
      return {
        i : 0,
        dateData:null,
        description: '个人客户信息表管理页面',
        // 表头
        url: {
          list: "/sendMsg/sendMsgDate/list",
          delete: "/sendMsg/sendMsgDate/delete",
          deleteBatch: "/sendMsg/sendMsgDate/deleteBatch",
          exportXlsUrl: "/sendMsg/sendMsgDate/exportXls",
          importExcelUrl: "/sendMsg/sendMsgDate/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    beforeCreate() {
      var date = new Date();
      httpAction('/sendMsg/sendMsgDate/queryByYear',{year : date.getFullYear()},'POST').then((res)=>{
        if(res.success){
          if(this.dateData == undefined){
            this.dateData = res.result
          }
        }
      })

    },
    created() {
    },
    computed: {
     importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      showModal: function(){
        this.$refs.editCalendarModal.showModal("add");
      },
      test(event){
        for(let key of event){
          //do something....
          /*alert(key.content)*/

        }
      },
      refurbish(){
        this.dateData = null;
        var date = new Date();
        httpAction('/sendMsg/sendMsgDate/queryByYear',{year : date.getFullYear()},'POST').then((res)=>{
          if(res.success){
            if(this.dateData == undefined){
              this.dateData = res.result
            }
          }
        })
      },
      onPanelChange(value, mode) {
        console.log(value, mode);
      },
      onSelect(value ){
        console.log(value.month()+1)
        console.log(moment(value).format('YYYY-MM-DD HH:mm:ss'))
      },
      change(moment){
        console.log("__"+moment)
      },
      getListData(value) {
        let listData = [];

        if(this.dateData.length > 0) {

          for (let i = 0; i < this.dateData.length; i++) {
            console.log(this.dateData[i].sjrq)
            var arr = this.dateData[i].sjrq.split("-")
            if (value.year() == arr[0] && value.month() + 1 == arr[1] && value.date() == arr[2]) {
              if(this.dateData[i].param != undefined && this.dateData[i].param != ""){
                var split = this.dateData[i].param.split("*")

                for (let i = 0; i < split.length; i++) {
                  var split1 = split[i].split("_")
                  if(split1[0].indexOf("LCXCTJ")!= -1){
                    let hour = split1[0].substring(0,1)
                    let reportId  = split1[0].substring(2)

                    let v= { type: 'warning', content: hour+"点"+reportId+"提交"+split1[1] }
                    listData.push(v)
                  }else{
                    let v= { type: 'warning', content: split1[0]+"点提交"+split1[1] }
                    listData.push(v)
                  }

                }
              }

            }
          }
          return listData || [];
        }
      },
      getMonthData(value) {
        /*if (value.month() === 8) {
          return 1394;
        }*/
      },
      moment,
      disabledDate(current) {
        httpAction('/customerinfo/privatecustomer/llbbPrivateCustomer',{"bankNoCd":"","sjrq":this.sjrq},'POST').then((res)=>{
          if(res.success){
            this.confirmLoading = true;
            this.confirmLoading = false;
            this.visible = false;
            this.handleAdd(this.model.bankNoCd,this.sjrq);
          }else{
            this.$message.warning(res.message)
          }
        })
        let rq = moment(current.toLocaleString()).format("YYYY-MM-DD");
        console.log("aaaa "+rq)
        // Can not select days before today and today
        return true;
      },
      showH(record){
        this.$refs.showhmodal.title = "查看历史";
        this.$refs.showhmodal.show(record);
        this.$refs.showhmodal.disableSubmit = true;
      },
      showSjrq: function(){
        that.$refs.SjrqModal.reportId = 'GRKHXX';
        this.$refs.SjrqModal.showModal("add");
      },
      handleAdd: function (frbs,sjrq) {
        that.$refs.modalForm.frbs = frbs;
        that.$refs.modalForm.sjrq = sjrq;
        that.$refs.modalForm.add();
        that.$refs.modalForm.title = "新增";
        that.$refs.modalForm.disableSubmit = false;
      },
      handleExport: function (fileName) {
        this.$refs.daochuModalForm.showModal(fileName,this.getQueryParams());
        this.$refs.daochuModalForm.title = "导出";
        this.$refs.daochuModalForm.disableSubmit = false;
      },
      initDictConfig(){
      },
      downloadIntData() {
        let fileName = "日历管理数据";
        let param = "";
        downFile("/sendMsg/sendMsgDate/exportXls",param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xlsx')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xlsx')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      downLoadExcel() {
        let fileName = "日历管理";
        let param = "";
        downFile("/sendMsg/sendMsgDate/downLoadExcel",param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xlsx')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xlsx')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      downLoadExcel() {
        let fileName = "日历管理";
        let param = "";
        downFile("/sendMsg/sendMsgDate/downLoadExcel",param).then((data)=>{
          if (!data) {
            this.$message.warning("文件下载失败")
            return
          }
          if (typeof window.navigator.msSaveBlob !== 'undefined') {
            window.navigator.msSaveBlob(new Blob([data],{type: 'application/vnd.ms-excel'}), fileName+'.xlsx')
          }else{
            let url = window.URL.createObjectURL(new Blob([data],{type: 'application/vnd.ms-excel'}))
            let link = document.createElement('a')
            link.style.display = 'none'
            link.href = url
            link.setAttribute('download', fileName+'.xlsx')
            document.body.appendChild(link)
            link.click()
            document.body.removeChild(link); //下载完成移除元素
            window.URL.revokeObjectURL(url); //释放掉blob对象
          }
        })
      },
      customRequest(data){
        this.downloadFile (data.file);
      },
      downloadFile (file) {
        var name = file.name
        var list_name = "日历管理.xlsx";
        let formData = new FormData();
        formData.append("file", file);
        this.axios.post(`${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`,formData,{'responseType': "blob"},).then(response=>{
          this.export_excel_file(response, list_name);
        })
      },
      export_excel_file(export_data,list_name){
        this.loading = true;
        let link = document.createElement("a");
        //    type就是blob的type,是MIME类型的，可以自己查看MIME类型都有哪些
        let blogw = new Blob([export_data],{type:"application/vnd.ms-excel;charset=utf-8"})
        let objectUrl = window.URL.createObjectURL(blogw);    //创建一个新的url对象
        link.href = objectUrl;
        let file_name = list_name
        link.download = file_name;    //  下载的时候自定义的文件名
        link.click();
        window.URL.revokeObjectURL(objectUrl);   //为了更好地性能和内存使用状况，应该在适当的时候释放url.
        this.refurbish()
        this.loading = fasle;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
  .events {
    list-style: none;
    margin: 0;
    padding: 0;
  }
  .events .ant-badge-status {
    overflow: hidden;
    white-space: nowrap;
    width: 100%;
    text-overflow: ellipsis;
    font-size: 12px;
  }
  .notes-month {
    text-align: center;
    font-size: 28px;
  }
  .notes-month section {
    font-size: 28px;
  }

</style>